<template>
  <div class="dwWarnEarthDetailWrap">
    <van-popup
      v-model="showArea"
      :close-on-click-overlay="false"
      position="bottom"
      :style="{ width: '100%', height: '100%' }"
    >
      <van-nav-bar
        title="预警信息"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
      />
      <div
        class="listArea"
        v-scrollBottom="scrollBottomMet"
        infinite-scroll-distance="10"
      >
        <div
          class="listLine"
          v-for="(item, index) in listData"
          :key="Number(index)"
          @click="toDetailFile(item)"
        >
          <div class="listLeft">
            <img
              :src="
                require(`@/assets/forecast/${item.imageType}-${item.degree}.png`)
              "
              alt
            />
          </div>
          <div class="listRight">
            <div class="listCon">
              <span>{{ item.alarmHeadline }}</span>
            </div>
            <div class="listTime">
              <span>有效日期：</span>
              <span>{{ item.alarmEffective }}</span>
            </div>
          </div>
        </div>
        <div v-if="noData" class="noData">
          <span>暂无更多数据</span>
        </div>
      </div>

      <div class="yujingtop" v-if="showDetail">
        <detail
          @detailBack="showDetail = false"
          :nowClickItem="nowClickItem"
        ></detail>
      </div>
    </van-popup>
  </div>
</template>
<script type="text/javascript">
import meteoroDisasterWarningApi from '@/service/disasterWarning.js'
import detail from '@/components/disasterWarning/detail.vue'
export default {
  props: {
    clickItem: {
      type: Object,
      default: () => {},
    },
  },
  data() {
    return {
      showArea: true,
      page: {
        limit: 20,
        page: 1,
      },
      listData: [],
      total: 0,
      noData: false,
      city: [
        '太原市',
        '大同市',
        '阳泉市',
        '长治市',
        '晋城市',
        '朔州市',
        '晋中市',
        '运城市',
        '忻州市',
        '临汾市',
        '吕梁市',
      ],
      alarmSenderParams: '',
      nowClickItem: {},
      showDetail: false,
    }
  },
  mounted() {
    this.forMatItem()
  },
  watch: {},
  components: {
    detail,
  },
  methods: {
    onClickLeft() {
      this.$emit('close')
    },
    forMatItem() {
      var clickCity = ''
      let cnty = ''
      this.city.forEach((item) => {
        if (this.clickItem.location.includes(item)) {
          clickCity = item
        }
      })
      if (clickCity == this.clickItem.location) {
        this.alarmSenderParams = this.clickItem.location
      } else {
        let cnty = this.clickItem.location.split(clickCity)[1]
        this.alarmSenderParams = cnty
      }
      this.initSXDwApi()
    },
    //查询山西省预报数据
    initSXDwApi() {
      if (!this.alarmSenderParams) return
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true,
        duration: 0,
      })
      var params = {
        alarmSender: `${this.alarmSenderParams}气象`,
        limit: this.page.limit,
        page: this.page.page,
      }
      meteoroDisasterWarningApi
        .get_tb_alarm_findByCon(params)
        .then((res) => {
          if (res.code == 0 && res.data.length != 0) {
            if (this.listData.length == 0) {
              this.listData = this.$util.getDwType(res.data)
            } else {
              var formatArr = this.$util.getDwType(res.data)
              formatArr.forEach((item) => {
                this.listData.push(item)
              })
            }
            this.total = res.total
            if (this.listData.length >= this.total) {
              this.noData = true
            }
          } else {
            this.noData = true
          }
          console.log(this.listData, 'fsfsdfdsfdsfadsfsdfdsfsfdd')
          this.$toast.clear()
        })
        .catch((error) => {
          this.$toast.clear()
        })
    },
    toDetailFile(item) {
      this.nowClickItem = item
      this.showDetail = true
    },
    scrollBottomMet() {
      if (this.noData) {
        return
      }
      //下一页
      this.page.page++
      //请求
      this.initSXDwApi()
    },
  },
}
</script>
<style type="text/css" lang="less" scoped>
.dwWarnEarthDetailWrap {
  /deep/ .van-nav-bar {
    background: #1989fa !important;
    margin-bottom: 20px;
  }
  .listArea {
    position: absolute;
    left: 0px;
    right: 0px;
    top: 50px;
    bottom: 0px;
    overflow-y: auto;
    background: white;
    border-radius: 10px;
    .listLine {
      overflow: hidden;
      padding: 15px 25px;
      border-bottom: 1px solid #ebedf0;
    }
    .listLeft {
      display: inline-block;
      vertical-align: middle;
      img {
        width: 30px;
      }
    }
    .listRight {
      vertical-align: middle;
      display: inline-block;
      font-size: 16px;
      margin-left: 10px;
      width: 85%;
      .listCon {
        margin-bottom: 10px;
      }
      .listTime {
        font-size: 12px;
        color: #999;
      }
    }
  }
}
</style>
